import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import './native_view_example.dart';

class NativePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Native View'),
      ),
      body: Center(
        child: Column(
          children: [
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                const platform = MethodChannel('plugins.methods/flnative_plugin');
                platform.invokeMethod('changeTextColor');
              }, 
              child: const Text('改变原生label文字颜色'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                const platform = MethodChannel('plugins.methods/flnative_plugin');
                List<Map> args = [{'showStr': 'The Text from Flutter'}];
                platform.invokeMethod('changeText', args);
              }, 
              child: const Text('改变原生label文字内容'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                const platform = MethodChannel('plugins.methods/flnative_plugin');
                List<Map> args = [{'pageName': 'xxx'}];
                platform.invokeMethod('openNativePage', args);
              }, 
              child: const Text('打开原生页面'),
            ),
            const SizedBox(height: 20),
            Platform.isIOS ? SizedBox(
              height: 100,
              child: NativeViewE(
                callAction: (args) {
                  String showStr = args['showStr'];
                  Fluttertoast.showToast(msg: showStr, gravity: ToastGravity.CENTER);
                },
              ),
            ) : const Text('其他平台暂不支持'),
          ],
        ),
      ),
    );
  }
}